package com.kangfu.api.controller;

import com.kangfu.api.interceptor.AuthorizationInterceptor;
import com.kangfu.api.service.IMedicalRecordService;
import com.kangfu.common.exception.BusinessException;
import com.kangfu.common.model.AjaxResult;
import com.kangfu.db.model.vo.MedicalRecordInfoVo;
import com.kangfu.db.model.vo.MedicalRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/medicalRecord")
public class MedicalRecordController {

    @Autowired
    public IMedicalRecordService medicalRecordService;


    @GetMapping("/list")
    public AjaxResult getMedicalRecordList(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId, @RequestParam(name = "page", defaultValue = "1") int page) {
        List<MedicalRecordVo> list = medicalRecordService.getMedicalRecordList(userId, page);
        return AjaxResult.success(list);
    }


    @GetMapping("/info")
    public AjaxResult getMedicalRecordInfo(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId, @RequestParam(name = "id" , defaultValue = "0") int id) {
        if (id <= 0) {
            throw new BusinessException("参数错误");
        }
        MedicalRecordInfoVo medicalRecordInfoVo = medicalRecordService.getMedicalRecordInfo(id);
        return AjaxResult.success(medicalRecordInfoVo);
    }
}
